import { createRouter, createWebHashHistory} from "vue-router";
let routesList = [
    {name: 'xmindTest'},
    {name: 'customNodes'},
    {name: 'dynamicForms'},
    {name: 'echartsTest'},
    {name: 'exportHtml'},
    {name: 'gridLayout'},
    {name: 'openLayers'},
    {name: 'filePreview'},
    {name: 'draggableBox'},
    {name: 'signatureDiv'},
]

let childrenRoute = []

routesList.forEach(e => {
    childrenRoute.push({
        path: '/account/' + e.name,
        name: e.name,
        meta: {
            title: e.name,
        },
        component: () => import('/src/views/' + e.name + '/index.vue')
    })
})

let routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'login',
        meta: {
            title: '登录'
        },
        component: () => import('/src/views/login/index.vue'),
    },
    {
        path: '/page1',
        name: 'Page1',
        meta: {
            title: '发送页'
        },
        component: () => import('/src/views/twoPage/page1.vue'),
    },
    {
        path: '/page2',
        name: 'Page2',
        meta: {
            title: '接收页'
        },
        component: () => import('/src/views/twoPage/page2.vue'),
    },
    {
        path: '/openLayers2',
        name: 'openLayers2',
        meta: {
            title: '接收页'
        },
        component: () => import('/src/views/openLayers/index2.vue'),
    },
    {
        path: '/account',
        name: 'account',
        redirect: '/account/customNodes',
        meta: {
            title: '后台管理'
        },
        component: () => import('/src/views/account/index'),
        children: childrenRoute
    },
    {
        path: '/quesKnow',
        name: 'quesKnow',
        meta: {
            title: '调查问卷'
        },
        component: () => import('/src/views/quesKnow/index'),
    },
]


const router = createRouter({
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to,from,next) => {
    document.title = to.meta.title
    next()
})

export default router
